﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.fminutes.vinciIsometric.pathfinding {

    public class MapGrid {

        private var _startNode:ANode;
        private var _endNode:ANode;
        private var _nodes:Array;
        private var _numCols:int;
        private var _numRows:int;
        private var _enlargeValue:int = 1;

        public function MapGrid(_arg1:int, _arg2:int){
            var _local4:int;
            super();
            this._numCols = _arg1;
            this._numRows = _arg2;
            this._nodes = [];
            var _local3:int;
            while (_local3 < this._numCols) {
                this._nodes[_local3] = [];
                _local4 = 0;
                while (_local4 < this._numRows) {
                    this._nodes[_local3][_local4] = new ANode(_local3, _local4);
                    _local4++;
                };
                _local3++;
            };
        }
        public function to3x3():void{
            var _local1:int;
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:int;
            if (this._enlargeValue == 3){
                return;
            };
            _local1 = 0;
            while (_local1 < this.numCols) {
                _local2 = 0;
                while (_local2 < this.numRows) {
                    if (this.getNode(_local1, _local2).walkable != 0){
                        if ((((((((_local1 <= 0)) || ((_local2 <= 0)))) || ((_local1 >= (this.numCols - 1))))) || ((_local2 >= (this.numRows - 1))))){
                            this.setWalkable(_local1, _local2, 666666);
                        } else {
                            _local3 = 1;
                            _local4 = -1;
                            while (_local4 < 2) {
                                _local5 = -1;
                                while (_local5 < 2) {
                                    if (this.getNode((_local1 + _local4), (_local2 + _local5)).walkable == 0){
                                        _local3 = 0;
                                        break;
                                    };
                                    _local5++;
                                };
                                if (_local3 == 0){
                                    break;
                                };
                                _local4++;
                            };
                            if (_local3 == 0){
                                this.setWalkable(_local1, _local2, 666666);
                            };
                        };
                    };
                    _local2++;
                };
                _local1++;
            };
            _local1 = 0;
            while (_local1 < this.numCols) {
                _local2 = 0;
                while (_local2 < this.numRows) {
                    if (this.getNode(_local1, _local2).walkable == 666666){
                        this.setWalkable(_local1, _local2, 0);
                    };
                    _local2++;
                };
                _local1++;
            };
            this._enlargeValue = 3;
        }
        public function getNode(_arg1:int, _arg2:int):ANode{
            return ((this._nodes[_arg1][_arg2] as ANode));
        }
        public function setEndNode(_arg1:int, _arg2:int):void{
            this._endNode = (this._nodes[_arg1][_arg2] as ANode);
        }
        public function setStartNode(_arg1:int, _arg2:int):void{
            this._startNode = (this._nodes[_arg1][_arg2] as ANode);
        }
        public function setWalkable(_arg1:int, _arg2:int, _arg3:int):void{
            this._nodes[_arg1][_arg2].walkable = _arg3;
        }
        public function get endNode():ANode{
            return (this._endNode);
        }
        public function get numCols():int{
            return (this._numCols);
        }
        public function get numRows():int{
            return (this._numRows);
        }
        public function get startNode():ANode{
            return (this._startNode);
        }
        public function toString():String{
            var _local3:int;
            var _local1 = "";
            var _local2:int;
            while (_local2 < this._numCols) {
                _local3 = 0;
                while (_local3 < this._numRows) {
                    if ((this._nodes[_local3][_local2] as ANode).walkable == 0){
                        _local1 = (_local1 + "@");
                    } else {
                        if ((this._nodes[_local3][_local2] as ANode).walkable > 1){
                            _local1 = (_local1 + "+");
                        } else {
                            _local1 = (_local1 + "-");
                        };
                    };
                    _local3++;
                };
                _local1 = (_local1 + "\n");
                _local2++;
            };
            return (_local1);
        }

    }
}//package com.fminutes.vinciIsometric.pathfinding 
